package com.softer.wxzj.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.softer.wxzj.common.entity.CommonResult;
import com.softer.wxzj.common.entity.Page;
import com.softer.wxzj.common.util.ShiroUserUtil;
import com.softer.wxzj.entity.SysCoreParam;
import com.softer.wxzj.mapper.SysCoreParamMapper;
import com.softer.wxzj.service.SysCoreParamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(rollbackFor = { RuntimeException.class, Exception.class })
public class SysCoreParamServiceImpl implements SysCoreParamService {
    @Autowired
    private SysCoreParamMapper syscoreparamMapper;
    @Override
    public CommonResult insert(SysCoreParam syscoreparam) {
        return null;
    }
    @Override
    public CommonResult update(SysCoreParam syscoreparam) {
        syscoreparam.setConfOper(ShiroUserUtil.getUserName());
        int i = syscoreparamMapper.update(syscoreparam);
        return CommonResult.ResponseResult(i);
    }

    @Override
    public CommonResult delete(String paramCode) {
        int i = syscoreparamMapper.delete(paramCode);
        return CommonResult.ResponseResult(i);
    }

    @Override
    public PageInfo<SysCoreParam> getList(Page page, SysCoreParam syscoreparam) {
        //只有紧跟在PageHelper.startPage方法后的第一个Mybatis的查询（Select）方法会被分页。
        PageHelper.startPage(page.getPageNum(), page.getPageSize());
        List<SysCoreParam> list = syscoreparamMapper.getList(syscoreparam);
        PageInfo<SysCoreParam> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }
    @Override
    public SysCoreParam getInfo(String paramCode) {
        return syscoreparamMapper.getInfo(paramCode);
    }

    @Override
   public PageInfo<SysCoreParam> fuzzySearch(Page page, String fuzzy, String paramType) {
        PageHelper.startPage(page.getPageNum(), page.getPageSize());
        List<SysCoreParam> list = syscoreparamMapper.fuzzySearch(fuzzy, paramType);
        PageInfo<SysCoreParam> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public String getParamByParamCode(String paramCode) {
        return syscoreparamMapper.getParamValueByCode(paramCode);
    }
}
